{%extends 'admin/layout.html'%}

{%block content%}
<style type="text/css">
#output {
    background-color: #000000;
    color: #fff;
    font-family: monospace, fixed;
    font-size: 15px;
    line-height: 18px;
}
</style>
<div class="mdui-container-fluid">
    <div class="mdui-typo">
        <h1>实时日志</h1>
    </div>
    <div class="mdui-row">
        <div class="mdui-tab" mdui-tab>
          <a href="{{url_for('admin.logs',logname='running')}}" class="mdui-ripple{%if logname=='running'%} mdui-tab-active{%endif%}">运行日志</a>
          <a href="{{url_for('admin.logs',logname='error')}}" class="mdui-ripple{%if logname=='error'%} mdui-tab-active{%endif%}">错误日志</a>
        </div>
    </div>
    <hr>
    <textarea class="mdui-textfield-input" rows="20" placeholder="" id="output"></textarea>
</div>
<script type="text/javascript">
    var source = new EventSource("{{url_for('admin.stream',command=command)}}");
    source.onmessage = function(event) {
        if(event.data=='end'){
            source.close();
        }
        else{
            document.getElementById("output").innerHTML += event.data + "\n";
            document.getElementById("output").scrollTop = document.getElementById('output').scrollHeight;
        }
      }
      source.addEventListener('error',function(e){
          source.close();
      })
</script>
{%endblock content%}
